package com.youyi.yyviewsdklibrary.View.searchview.utils;

import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import java.lang.reflect.Field;

public class EditTextReflectionUtils {
    private static final String EDIT_TEXT_FIELD_CURSOR_DRAWABLE = "mCursorDrawable";
    private static final String EDIT_TEXT_FIELD_CURSOR_DRAWABLE_RES = "mCursorDrawableRes";
    private static final String EDIT_TEXT_FIELD_EDITOR = "mEditor";
    private static final String TAG = "EditTextReflectionUtils";

    private EditTextReflectionUtils() {
    }

    public static void setCursorDrawable(EditText editText, int i) {
        try {
            Field declaredField = TextView.class.getDeclaredField(EDIT_TEXT_FIELD_CURSOR_DRAWABLE_RES);
            declaredField.setAccessible(true);
            declaredField.set(editText, Integer.valueOf(i));
        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }

    public static void setCursorColor(EditText editText, int i) {
        try {
            Field declaredField = TextView.class.getDeclaredField(EDIT_TEXT_FIELD_CURSOR_DRAWABLE_RES);
            declaredField.setAccessible(true);
            int i2 = declaredField.getInt(editText);
            Field declaredField2 = TextView.class.getDeclaredField(EDIT_TEXT_FIELD_EDITOR);
            declaredField2.setAccessible(true);
            Object obj = declaredField2.get(editText);
            Drawable drawable = ContextCompat.getDrawable(editText.getContext(), i2);
            drawable.setColorFilter(i, PorterDuff.Mode.SRC_IN);
            Drawable[] drawableArr = {drawable, drawable};
            Field declaredField3 = obj.getClass().getDeclaredField(EDIT_TEXT_FIELD_CURSOR_DRAWABLE);
            declaredField3.setAccessible(true);
            declaredField3.set(obj, drawableArr);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
}
